package com.ivan.toolkit.swing;

import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;

import javax.swing.SwingUtilities;
import javax.swing.border.MatteBorder;

public class AccordionPane extends TitledPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1703312502228590407L;
	
	private Component content = null;

	/**
	 * Create the panel.
	 */
	public AccordionPane() {
		super();
		this.getTitlePane().setBorder(new MatteBorder(1, 0, 0, 0, (Color) Color.LIGHT_GRAY));
		this.getTitlePane().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	}
	
	public void setContent(Component component) {
		
		if(content != null) {
			this.remove(content);
			content = null;
		}
		
		if(component != null) {
			this.add(component);
			content = component;
		}
		
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				SwingUtilities.updateComponentTreeUI(AccordionPane.this);
			}
			
		});
		//SwingUtilities.updateComponentTreeUI(this);

	}
	
	public Component getContent() {
		return this.content;
	}

}
